package com.example.demo.groovy;

import groovy.lang.Binding;
import groovy.lang.GroovyShell;

public class GroovyTest01 {
    public static class Toaster{
        private int toasted=0;
        public void toast(){
            System.out.println(++toasted);
        }
    }

    public static void main(String[] arg){
        Toaster toaster = new Toaster();
        Binding binding = new Binding();
        binding.setVariable("toaster", toaster);
        GroovyShell shell = new GroovyShell(binding);
        shell.evaluate("toaster.toast();");   // < prints 1
        shell.evaluate("toaster.toast();");   // < prints 2
        shell.evaluate("toaster.toast();");   // < prints 3
        shell.evaluate("toaster.toast();");   // < prints 4
    }
}
